package com.cx.controller;

import com.cx.dto.TaskDTO;
import com.cx.dto.TaskPageDTO;
import com.cx.service.TaskService;
import com.cx.util.PageResult;
import com.cx.util.ResultUtil;
import com.cx.vo.StatusAndCountOfTaskVO;
import com.cx.vo.TaskVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 晨曦
 * @Description: 任务接口
 * @DateTime: 2025/4/6 10:35
 **/
@RestController
@RequestMapping("/task")
@Slf4j
@Api(value = "任务接口")
@RequiredArgsConstructor
public class TaskController {

    private final TaskService taskService;
    @PostMapping("/addTask")
    @ApiOperation(value = "添加任务")
    public ResultUtil addTask(@RequestBody TaskDTO taskDTO){
        log.info("添加任务！taskDTO:{}",taskDTO);
        return taskService.addTask(taskDTO);
    }

    @GetMapping("/selectTaskById/{id}")
    @ApiOperation(value = "根据id查询任务")
    public ResultUtil<TaskVO> selectTaskById(@PathVariable("id") Integer id){
        log.info("根据id查询任务！id:{}",id);
        return taskService.selectTaskById(id);
    }
    @PutMapping("/updateTaskById")
    @ApiOperation(value = "根据id修改任务")
    public ResultUtil updateTaskById(@RequestBody TaskDTO taskDTO){
        log.info("根据id修改任务！ taskDTO:{}",taskDTO);
        return taskService.updateTaskById(taskDTO);
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultUtil<PageResult<TaskVO>> page(TaskPageDTO taskPageDTO){
        log.info("分页查询！taskPageDTO:{}",taskPageDTO);
        return taskService.page(taskPageDTO);
    }

    @PutMapping("/updateStatusById/{id}")
    @ApiOperation(value = "根据id修改状态")
    public ResultUtil updateStatusById(@PathVariable("id") Integer id){
        log.info("根据id修改状态!id:{}",id);
        return taskService.updateStatusById(id);
    }
    @DeleteMapping("/deleteTaskById/{id}")
    @ApiOperation(value = "根据id删除任务")
    public ResultUtil deleteTaskById(@PathVariable("id") Integer id){
        log.info("根据id删除任务！id：{}",id);
        return taskService.deleteTaskById(id);
    }

    @GetMapping("/selectStatusOfTasks")
    @ApiOperation("查询任务完成情况")
    public ResultUtil<List<StatusAndCountOfTaskVO>> selectStatusOfTasks(){
        log.info("查询任务完成情况");
        return taskService.selectStatusOfTasks();
    }
}
